#pragma once
#include <cstdlib>
#include <ctime>
#include "../lib3dw/ColladaModel.h"
#include "../lib3dw/DrawableObject.h"
#include "../lib3dw/Vector4.h"
#include "BoardTile.h"
#include "Player.h"

using namespace lib3dw;

namespace Dicewars
{
	typedef enum { BoardCoordinates, MouseCoordinates } TileSelectionMode;
	typedef enum { MoveDice, Attack, Cancel, Reselect } MoveMode;

	class Board : public DrawableObject
	{
		public:
			Board();
			~Board();
			void Draw();
			void SetHoveredTile(BoardTile* tile);
			void SetSelectedTile(BoardTile* tile);			
			ColladaModel* GetModel() const;
			BoardTile* GetBoardTile(unsigned int x, unsigned int y);
			BoardTile* GetSelectedTile() const;
			std::vector<BoardTile*> GetTilesOwnedByPlayer(Player* activePlayer) const;
			unsigned int CountTilesOwnedByPlayer(Player* activePlayer);
			const bool MoveAllowed(BoardTile* start, BoardTile* end) const;
			const int GetWidth() const;
			const int GetHeight() const;		
			const MoveMode GetMoveMode(BoardTile* start, BoardTile* end, Player* activePlayer) const;
			const bool TileWithinBoardBounds(int x, int y) const;

		private:
			static const int width = 8;
			static const int height = 8;
			BoardTile* tiles[width][height];
			BoardTile* hoveredTile;
			BoardTile* selectedTile;
			ColladaModel* model;
			static const int bufferSize = 128;
			unsigned int selectBuf[bufferSize];
			unsigned int selectName;
			unsigned int selectCount;
	};
}